INCLUDE_DIRECTORIES(${SDL_INCLUDE_DIR} $<$<BOOL:${WIN32}>:${GLEW_INCLUDE_DIRS}>)

SET(COMMON_FILES COCOA SDLVideo.cpp SDLSurfaceSprite2D.cpp DPadSoftKeyboard.cpp)

IF(SDL_BACKEND STREQUAL "SDL2")
	# With v2.24, we get libSDL2main, and that wants main() be linked here.
	IF(SDL2_SDL2main_FOUND)
		STRING(REPLACE "SDL2::SDL2main" "" SDL_LIBRARY "${SDL_LIBRARY}")
	ENDIF()

	IF(NOT OPENGL_BACKEND STREQUAL "None")
		ADD_GEMRB_PLUGIN(SDLVideo ${COMMON_FILES} SDL20Video.cpp GLSLProgram.cpp)
		target_compile_definitions(SDLVideo PRIVATE USE_OPENGL_BACKEND)
		target_compile_definitions(SDLVideo PRIVATE USE_$<UPPER_CASE:${OPENGL_BACKEND}_API>)
		TARGET_LINK_LIBRARIES(SDLVideo ${SDL_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${COCOA_LIBRARY_PATH})

		IF(OPENGL_BACKEND STREQUAL "OpenGL")
			TARGET_LINK_LIBRARIES(SDLVideo ${OPENGL_LIBRARIES})
			IF(WIN32)
				TARGET_LINK_LIBRARIES(SDLVideo ${GLEW_LIBRARIES})  
			ENDIF()
		ELSE()
			TARGET_LINK_LIBRARIES(SDLVideo ${OPENGLES2_LIBRARIES})
		ENDIF()

		# Shaders are installed in gemrb/CMakeLists.txt for better mac compatibility
		# also copy to the build dir for no-install runs
		FILE(COPY Shaders DESTINATION ${CMAKE_BINARY_DIR})
	ELSE()
		ADD_GEMRB_PLUGIN(SDLVideo ${COMMON_FILES} SDL20Video.cpp)
		TARGET_LINK_LIBRARIES(SDLVideo ${SDL_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${COCOA_LIBRARY_PATH})
	ENDIF()

	IF(MINGW)
		TARGET_LINK_LIBRARIES(SDLVideo imm32 winmm version)
	ENDIF()
ELSE()
	ADD_GEMRB_PLUGIN (SDLVideo ${COMMON_FILES} SDL12Video.cpp)
	TARGET_LINK_LIBRARIES(SDLVideo ${SDL_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${COCOA_LIBRARY_PATH})
ENDIF()

target_compile_definitions(SDLVideo PRIVATE _USE_MATH_DEFINES)
